<?php

class sxMerchant
{
    /**
     *
     * @param type $wsdl
     * @param type $sourceKey
     * @param type $pin 
     * 
     * @see http://pear.php.net/package/SOAP
     */
    public function __construct($wsdl, $sourceKey, $pin)
    {
        //set the client wsdl + token 
        $this->setClient($wsdl);
        $this->setToken($sourceKey, $pin);
    }

    private function setClient($wsdl)
    {
        //set the client
        $this->client = new baseUSAEpayService(array('wsdl' => $wsdl));
    }

    /**
     *
     * @param string $sourceKey '0QB2S1e1o1N7LUy7C91T9VbBcJU8B6z4';
     * @param string $pin Input the PIN set in the source editor for your source key
     * @return array 
     * 
     */
    private function setToken($sourceKey, $pin)
    {
        // generate random seed value
        $seed = time() . rand();

        // make hash value using sha1 function
        $hash = sha1($sourceKey . $seed . $pin);

        // assembly ueSecurityToken as an array
        // (php5 will correct the type for us)
        $tok = array(
            'SourceKey' => $sourceKey,
            'PinHash' => array(
                'Type' => 'sha1',
                'Seed' => $seed,
                'HashValue' => $hash
            ),
            'ClientIP' => '127.0.0.1',
        );

        $this->token = $tok;
    }

    /**
     *
     * @return array token
     */
    public function getToken()
    {
        return $this->token;
    }

    /**
     *
     * @return SoapClient
     */
    public function getClient()
    {
        return $this->client;
    }

}